//
//  PLInteraction.h
//  Plankton
//
//  Created by Marc Schlichte on 2008-07-17.
//  Copyright 2008 Framework Labs. All rights reserved.
//

#import <Cocoa/Cocoa.h>


@class PLPlatform, PLPattern;

@interface PLInteraction : NSObject
{
    NSString        *aid;
    PLPlatform      *platform;
    id              target;
    
    NSNumber        *iid;
    NSMutableDictionary *dict;
    
    SEL             doneAction;
    NSTimeInterval  timeout;
    SEL             timeoutAction;    
}

@property SEL               doneAction;
@property NSTimeInterval    timeout;
@property SEL               timeoutAction;

- (void)establishNewIid;

@end


/*!
    @class
    @abstract    Captures the interaction of multicast request-reply protocols
    @discussion  This class captures the boilerplate and logig needed to send
                 requests to multiple receivers and handle their replies.
*/
@interface PLMulticastRequestReplyInteraction : PLInteraction 
{
    NSString        *performative;
    
    NSMutableSet    *peers;
    
    SEL             receiveRequestAction;
    SEL             receiveReplyAction;
    
    PLPattern       *receiveRequestsPattern;
    NSString        *sender;
}

+ (PLMulticastRequestReplyInteraction *)interactionForAid:(NSString *)aid 
                                             performative:(NSString *)perf
                                                 platform:(PLPlatform *)platform 
                                                   target:(id)target;

@property SEL receiveReplyAction;
@property SEL receiveRequestAction;

- (void)sendRequests:(id)message to:(NSSet *)aids;
- (void)receiveRequests;
- (void)sendReply:(id)message;

@end
